#include"HttpServer.hpp"
#include"Session.hpp"
void Login(HttpRequest& req, HttpResponse& resp)
{
    //根据req，动态构建resp
    std::cout<<"进入登录模块"<<req.Path()<<" , "<<req.Args()<<std::endl;
    std::string req_args=req.Args();
    
    //1.解析参数格式，得到要的参数
    
    //2.访问数据库
    //TODO
    // SessionManager m;
    // uint64_t session_id=m.CreateSession();

    //3.登录成功
    std::string body=req.GetContent("wwwroot/succuss.html");
    resp.SetCode(200);
    resp.SetHeader("Content-Length",std::to_string(body.size()));
    resp.SetHeader("Content-Type","text/html");
    resp.SetHeader("Set-Cookie","username=lisi;passwd=hahahah");
    resp.SetBody(body);
    //也可以完成重定向功能

}
 
void Search(HttpRequest& req, HttpResponse& res)
{
    //根据req，动态构建resp
    std::cout<<"进入登录模块"<<req.Path()<<" , "<<req.Args()<<std::endl;
    
}

void Register(HttpRequest& req, HttpResponse& res)
{
    //根据req，动态构建resp
    std::cout<<"进入登录模块"<<req.Path()<<" , "<<req.Args()<<std::endl;
    
}

int main(int argc, char* argv[])
{   
    if(argc!=2)
    {
        std::cout<<"参数太少了"<<std::endl;
        return -1;
    }
    printf("Http Server 正在运行，端口号：%s\n", argv[1]);
    auto httpserver = std::make_unique<HttpServer>(std::stoi(argv[1]));
    //添加服务器功能
    //要让服务器具有登录功能
    httpserver->Resgiterstd("/login",Login);
    httpserver->Resgiterstd("/register",Register);
    httpserver->Resgiterstd("/search",Search);
    httpserver->Start();
    return 0;   
}
